<?php

/**
 * This is the model class for table "movie".
 *
 * The followings are the available columns in table 'movie':
 * @property string $id
 * @property string $title
 * @property string $subject
 * @property string $image
 * @property string $small_image
 * @property string $source_image
 * @property integer $free_image
 * @property integer $year
 * @property string $duration
 * @property integer $hidden
 * @property string $wikipedia_url
 * @property string $youtube_id
 * @property string $kp_id
 * @property string $kp_rating
 * @property string $imdb_rating
 * @property string $language_id
 */
class Movie extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Movie the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'movie';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('title, language_id', 'required'),
            array('year', 'numerical', 'integerOnly' => true),
            array('free_image, hidden', 'boolean'),
            array('title, image, small_image, source_image, wikipedia_url, youtube_id', 'length', 'max' => 255),
            array('duration, kp_id, language_id', 'length', 'max' => 10),
            array('kp_rating, imdb_rating', 'length', 'max' => 4),
            array('subject', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, title, free_image, year, duration, hidden, wikipedia_url, youtube_id, kp_id, kp_rating, imdb_rating, language_id', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'language' => array(self::BELONGS_TO, 'Language', 'language_id', 'together' => true),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => Yii::t('default', 'ID'),
            'title' => Yii::t('default', 'Title'),
            'code' => Yii::t('default', 'Code'),
            'subject' => Yii::t('default', 'Subject'),
            'image' => Yii::t('default', 'Image'),
            'small_image' => Yii::t('default', 'Small Image'),
            'source_image' => Yii::t('default', 'Source Image'),
            'free_image' => Yii::t('default', 'Free Image'),
            'year' => Yii::t('default', 'Year'),
            'duration' => Yii::t('default', 'Duration'),
            'hidden' => Yii::t('default', 'Hidden'),
            'wikipedia_url' => Yii::t('default', 'Wikipedia URL'),
            'youtube_id' => Yii::t('default', 'Youtube ID'),
            'kp_id' => Yii::t('default', 'KinoPoisk ID'),
            'kp_rating' => Yii::t('default', 'KinoPoisk Rating'),
            'imdb_rating' => Yii::t('default', 'IMDb Rating'),
            'language_id' => Yii::t('default', 'Language'),
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('title', $this->title, true);
        $criteria->compare('free_image', $this->free_image);
        $criteria->compare('year', $this->year);
        $criteria->compare('duration', $this->duration, true);
        $criteria->compare('hidden', $this->hidden, true);
        $criteria->compare('wikipedia_url', $this->wikipedia_url, true);
        $criteria->compare('youtube_id', $this->youtube_id, true);
        $criteria->compare('kp_id', $this->kp_id, true);
        $criteria->compare('kp_rating', $this->kp_rating, true);
        $criteria->compare('imdb_rating', $this->imdb_rating, true);
        $criteria->compare('language_id', $this->language_id, true);

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

}